/* 
*  Copyright (C) 2009-2010 WCG Project
*
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the
*  Free Software Foundation; either version 2 of the License, or (at
*  your option) any later version.
*
*  This program is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*  General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software Foundation,
*  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*  In addition, as a special exception, the author gives permission to
*  link the code of this program with the Half-Life Game Engine ("HL
*  Engine") and Modified Game Libraries ("MODs") developed by Valve,
*  L.L.C ("Valve"). You must obey the GNU General Public License in all
*  respects for all of the code used other than the HL Engine and MODs
*  from Valve. If you modify this file, you may extend this exception
*  to your version of the file, but you are not obligated to do so. If
*  you do not wish to do so, delete this exception statement from your
*  version.
*/



public MOTD_ItemsInfo( id, iStart )
{

	static szTmp[256], szTmp2[256], pos, i

	pos = 0

	// Add header
	pos += formatex( szTmpMsg[pos], 2047-pos, "%s", MOTD_header )

	// Add the item information
	for ( i = iStart; i < MAX_ITEMS_PAGE + iStart; i++ )
	{
		LANG_GetItemInfo( i, id, szTmp, 127 )
		LANG_GetItemName( i, id, szTmp2, 127 )

		pos += formatex( szTmpMsg[pos], 2047-pos, "<li>%s</li><div id='s'>%s</div><br>", szTmp, szTmp2 )
	}

	if ( iStart == 0 )
		formatex( szTmp, 127, "%L", id, "MOTD_TITLE_SHOPMENU" )
	else
		formatex( szTmp, 127, "%L", id, "MOTD_TITLE_SHOPMENU2" )

	show_motd( id, szTmpMsg, szTmp )
}




public MOTD_PlayerSkills( id, bool:bThroughSay )
{
	// Lets find out what races are in use
	new bool:bRaceUsed[MAX_CLASSES+1] = {false}, iRaceID, iTargetID

	for( iTargetID = 1; iTargetID <= GameInfo[GI_MaxPlayers] ; iTargetID++ )
	{
		if( !is_user_connected(iTargetID) || !IsOnTeam(iTargetID) )
			continue

		iRaceID = PlayerInfo[iTargetID][PI_Class]

		bRaceUsed[iRaceID] = true
	}
	
	static szRaceName[64]
	new pos = 0, iTeam, szTeamColor[2]

	// Then we have a player, and we're not on the server console
	if ( id != 0 && bThroughSay )
		pos += formatex( szTmpMsg[pos], 2047 - pos, "%s", MOTD_header )

	// Loop through each race
	for( iRaceID = 1 ; iRaceID <= MAX_CLASSES ; iRaceID++ )
	{
		// Make sure this race was used somewhere!
		if( !bRaceUsed[iRaceID] )
			continue

		// Get the class name
		LANG_GetClassName( iRaceID, id, szRaceName, 63 )

		// Player
		if( id != 0 && bThroughSay )
			pos += formatex( szTmpMsg[pos], 2047 - pos, "<b>%s</b><ul>", szRaceName )

		// Server Console
		else
		{
			if( id == 0 )
				server_print( "**** %s ****", szRaceName )
			else
				console_print( id, "**** %s ****", szRaceName )
		}


		// Lets show them per team, T, then CT, then Spectators
		for( iTeam = TEAM_T ; iTeam <= TEAM_CT + 1 ; iTeam++ )
		{
			
			// Default color
			formatex( szTeamColor, 1, "p" )

			if( iTeam == TEAM_T )
				formatex( szTeamColor, 1, "t" )

			else if( iTeam == TEAM_CT )
				formatex( szTeamColor, 1, "c" )


			// Loop through all players
			for( iTargetID = 1 ; iTargetID <= GameInfo[GI_MaxPlayers] ; iTargetID++ )
			{
				// Make sure the user has this race and is on the proper team
				if( !is_user_connected(iTargetID) || PlayerInfo[iTargetID][PI_Class] != iRaceID || PlayerInfo[iTargetID][PI_TeamID] != iTeam )
					continue

				// Player
				if( id != 0 && bThroughSay )
					pos += formatex( szTmpMsg[pos], 2047 - pos, "<li id='%s'>(%d) %s</li>", szTeamColor, PlayerInfo[iTargetID][PI_Level], PlayerInfo[iTargetID][PI_PlayerName] )

				// Server Console
				else
				{
					static szTeamName[32]
				
					get_user_team( id, szTeamName, 31 )

					new iTeamID = PlayerInfo[iTargetID][PI_TeamID]

					if( id == 0 )
						server_print( "  [%s]:%d %s", g_TeamNames[iTeamID], PlayerInfo[iTargetID][PI_Level], PlayerInfo[iTargetID][PI_PlayerName] )
					else
						console_print( id, "  [%s]:%d %s", g_TeamNames[iTeamID], PlayerInfo[iTargetID][PI_Level], PlayerInfo[iTargetID][PI_PlayerName] )
				}
			}
		}

		// Player
		if( id != 0 && bThroughSay )
			pos += formatex( szTmpMsg[pos], 2047 - pos, "</ul>" )

	}

	// Player
	if( id != 0 && bThroughSay )
	{
		static szTitle[128]
		formatex( szTitle, 127, "%L", id, "PLAYER_SKILLS" )

		show_motd( id, szTmpMsg, szTitle )
	}
}



public MOTD_SkillsInfo( id )
{

	new iSkillID, bool:bHeaderShown, pos
	static szTitle[128], szTmpDesc[256], szSkillName[128], szRaceName[64]

	pos = 0
	pos += formatex( szTmpMsg[pos], 2047-pos, "%s", MOTD_header )

	// Valid race found!
	if( IsValidClass( PlayerInfo[id][PI_Class] ) )
	{
		// Get the class name
		LANG_GetClassName( PlayerInfo[id][PI_Class], id, szRaceName, 63 )

		// format the title
		pos += formatex( szTmpMsg[pos], 2047-pos, "<div id=^"title^">%s</div><br><br>", szRaceName )
		
		// Format the MOTD title
		formatex( szTitle, 127, "%s %L", szRaceName, id, "WORD_INFORMATION" )
	}

	// No race selected
	else
	{
		pos += formatex( szTmpMsg[pos], 2047-pos, "<div id=^"title^">No Race Selected</div><br><br>" )

		// Format the MOTD title
		formatex( szTitle, 127, "Skills Information" )
	}


	// Lets get the trainable skills first!

	bHeaderShown = false
	iSkillID = SM_GetSkillOfType( id, SKILL_TYPE_TRAINABLE )
	while( iSkillID != SKILL_NONE )
	{
		if ( !bHeaderShown )
		{
			pos += formatex( szTmpMsg[pos], 2047-pos, "<h1>%L</h1>", id, "WORD_TRAINABLE_SKILLS" )
			bHeaderShown = true
		}

		LANG_GetSkillName( iSkillID, id, szSkillName, 127, 2 )
		LANG_GetSkillInfo( iSkillID, id, szTmpDesc, 255 )

		pos += formatex( szTmpMsg[pos], 2047-pos, "<li>%s</li><ul>%s</ul><br>", szSkillName, szTmpDesc )

		iSkillID = SM_GetSkillOfType( id, SKILL_TYPE_TRAINABLE, iSkillID )
	}


	bHeaderShown = false
	iSkillID = SM_GetSkillOfType( id, SKILL_TYPE_ABILITY )
	while( iSkillID != SKILL_NONE )
	{
		if( !bHeaderShown )
		{
			pos += formatex( szTmpMsg[pos], 2047-pos, "<h1>Abilities</h1>" )
			bHeaderShown = true
		}

		LANG_GetSkillName( iSkillID, id, szSkillName, 127, 2 )
		LANG_GetSkillInfo( iSkillID, id, szTmpDesc, 255 )

		pos += formatex( szTmpMsg[pos], 2047-pos, "<li>%s</li><ul>%s</ul><br>", szSkillName, szTmpDesc )

		iSkillID = SM_GetSkillOfType( id, SKILL_TYPE_ABILITY, iSkillID )
	}

	bHeaderShown = false
	iSkillID = SM_GetSkillOfType( id, SKILL_TYPE_ULTIMATE )
	while( iSkillID != SKILL_NONE )
	{
		if ( !bHeaderShown )
		{
			pos += formatex( szTmpMsg[pos], 2047-pos, "<h1>%L</h1>", id, "WORD_ULTIMATE" )
			bHeaderShown = true
		}

		LANG_GetSkillName( iSkillID, id, szSkillName, 127, 3 )
		LANG_GetSkillInfo( iSkillID, id, szTmpDesc, 255 )

		pos += formatex( szTmpMsg[pos], 2047-pos, "<li>%s</li><ul>%s</ul>", szSkillName, szTmpDesc )

		iSkillID = SM_GetSkillOfType( id, SKILL_TYPE_ULTIMATE, iSkillID )
	}


	show_motd( id, szTmpMsg, szTitle )
}


public MOTD_AttributesInfo( id )
{
	static pos, szTitle[128], szTmpDesc[256], szAttributeName[128]

	pos = 0
	pos += formatex( szTmpMsg[pos], 2047-pos, "%s", MOTD_header )

	pos += formatex( szTmpMsg[pos], 2047-pos, "<h1>%L</h1><br>", id, "WORD_ATTRIBUTES_INFORMATION" )

	for( new iAttribID = 0; iAttribID < MAX_ATTRIBUTES; iAttribID++ )
	{
		LANG_GetAttributeName( iAttribID, id, szAttributeName, 127, 2 )
		LANG_GetAttributeInfo( iAttribID, id, szTmpDesc, 255 )

		pos += formatex( szTmpMsg[pos], 2047-pos, "<li>%s</li><ul>%s</ul><br>", szAttributeName, szTmpDesc )
	}

	show_motd( id, szTmpMsg, szTitle )
}



public MOTD_War3help(id)
{
	// Get the game title
	static szGame[32]
	get_modname( szGame, 31 )

	new pos = 0

	// Add header
	pos += formatex( szTmpMsg[pos], 2047-pos, "%s", MOTD_header )

	// Add the content
	pos += formatex( szTmpMsg[pos], 2047-pos, "%L<br><br>"	, id, "MOTD_DEVELOPED_BY" )
	pos += formatex( szTmpMsg[pos], 2047-pos, "%L<br><br>"	, id, "MOTD_ORIGINAL_DEVELOPER" )
	pos += formatex( szTmpMsg[pos], 2047-pos, "%L<br>"	, id, "MOTD_CLICK_FOR_LATEST" )
	pos += formatex( szTmpMsg[pos], 2047-pos, "%L"		, id, "WCGHELP" )
	
	// Set up the title
	static szTitle[128]
	formatex( szTitle, 127, "%L", id, "WAR3HELP_TITLE" )

	show_motd( id, szTmpMsg, szTitle )
}
